package com.myk.game.sumeru.game;

import com.myk.game.sumeru.chesses.Chess_DevourSand;
import com.myk.game.sumeru.chesses.Chess_DivineTree;
import com.myk.game.sumeru.chesses.Chess_HunterKing;
import com.myk.game.sumeru.chesses.Chess_JugglingMaster;
import com.myk.game.sumeru.chesses.Chess_MadBull;
import com.myk.game.sumeru.chesses.Chess_MightyTiger;
import com.myk.game.sumeru.chesses.Chess_MushroomBeast;
import com.myk.game.sumeru.chesses.Chess_PoisonousSnake;
import com.myk.game.sumeru.chesses.Chess_ShadowAssassin;
import com.myk.game.sumeru.chesses.Chess_WarDancer;
import com.myk.game.sumeru.interfaces.IGameUI;

import java.util.List;
import java.util.Set;

/**
 * 个人模式游戏状态
 */
public class PersonalGame extends BaseGame {

    private Chess selectedChess;//当前选中要操作的棋子

    @Override
    public void init(IGameUI gameUI) {
        super.init(gameUI);
        start(); //个人模式直接自动开始
    }

    @Override
    public void start() {
        initChesses();
        initPutNeutralChess();
        ui.refreshChessBoard();
        waitLayoutChesses();
    }

    private void waitLayoutChesses() {
        for (Chess chess : chesses) {
            chess.setBeClickEvent(() -> {
                ui.showTip("点击了" + chess.NAME);
                //++判断棋子的归属，获取格子列表，设置提示图标，设置格子点击事件
                    //++格子的点击事件执行落子方法，关闭提示图标。
            });
        }
        ui.setGameButtons(makeGameButton("返回", ui::leave));
        ui.showTip("请摆放两边棋子的初始布局");
    }

    //初始化棋子
    private void initChesses() {
        chesses.clear();
        chesses.add(new Chess_MushroomBeast(this));
        chesses.add(new Chess_MushroomBeast(this));
        chesses.add(new Chess_MushroomBeast(this));
        chesses.add(new Chess_MushroomBeast(this));
        chesses.add(new Chess_MushroomBeast(this));
        chesses.add(new Chess_MushroomBeast(this));
        chesses.add(new Chess_MushroomBeast(this));
        chesses.add(new Chess_MushroomBeast(this));
        chesses.add(new Chess_MushroomBeast(this));

        chesses.add(new Chess_WarDancer(this, Chess.OTH));
        chesses.add(new Chess_JugglingMaster(this, Chess.OTH));
        chesses.add(new Chess_HunterKing(this, Chess.OTH));
        chesses.add(new Chess_ShadowAssassin(this, Chess.OTH));
        chesses.add(new Chess_MadBull(this, Chess.OTH));
        chesses.add(new Chess_MightyTiger(this, Chess.OTH));
        chesses.add(new Chess_PoisonousSnake(this, Chess.OTH));
        chesses.add(new Chess_DivineTree(this, Chess.OTH));
        chesses.add(new Chess_DevourSand(this, Chess.OTH));

        chesses.add(new Chess_WarDancer(this, Chess.OWN));
        chesses.add(new Chess_JugglingMaster(this, Chess.OWN));
        chesses.add(new Chess_HunterKing(this, Chess.OWN));
        chesses.add(new Chess_ShadowAssassin(this, Chess.OWN));
        chesses.add(new Chess_MadBull(this, Chess.OWN));
        chesses.add(new Chess_MightyTiger(this, Chess.OWN));
        chesses.add(new Chess_PoisonousSnake(this, Chess.OWN));
        chesses.add(new Chess_DivineTree(this, Chess.OWN));
        chesses.add(new Chess_DevourSand(this, Chess.OWN));
    }

    //给所有棋子添加事件，点击后：棋子高亮，界面下方展示棋子详细信息，棋盘上的村落显示可以被移动的圆圈，村落格子设置点击事件允许棋子落下。
    private void setChessesEventShowInfo() {
        for (Chess chess : chesses) {
            chess.setBeClickEvent(new Chess.ChessBeClickEvent() {
                @Override
                public void beClickEvent() {
                    ui.showTip("点击了" + chess.NAME);
                }
            });
        }
    }

    //放置中立棋子
    private void initPutNeutralChess() {
        List<Grid> lakeGrids = map.getLakeGrids();
        List<Chess> midChesses = getChesses(Chess.MID);
        for (int i = 0; i < lakeGrids.size(); i++) {
            midChesses.get(i).setPosition(lakeGrids.get(i));
            lakeGrids.get(i).setChess(midChesses.get(i));
        }
    }

}
